package com.xnyzc.lhy.common.util.validate;

import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;

import java.math.BigDecimal;
import java.util.regex.Pattern;

/**
 * @Description 金额校验
 * @Author zhuyubin
 * @Date 2019-09-20 15:54
 **/
public class validateMoneyUtil {

    /**
     * 额度校验
     * @param amount 额度
     */
    public static boolean validateAmount(BigDecimal amount){
        if (CheckUtil.objIsEmpty(amount)){
            return false;
        }
        // 校验金额
        String pattern = "^(([1-9][0-9]*)|(([0]\\.\\d{1,2}|[1-9][0-9]*\\.\\d{1,2})))$";
        Pattern p = Pattern.compile(pattern);
        return Pattern.matches(p.pattern(), amount.toString());
    }
}
